package com.hbwxz.admin.service;

import com.hbwxz.admin.pojo.CommodityBrand;
import com.hbwxz.admin.repo.CommodityBrandRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityBrandService {

    @Autowired
    private CommodityBrandRepository commodityBrandRepository;

    public void createBrand(CommodityBrand commodityBrand) {
        CommodityBrand cb = commodityBrandRepository.findByName(commodityBrand.getName());
        if(cb != null) {
            throw new RuntimeException("brand already exist");
        }
        commodityBrandRepository.save(commodityBrand);
    }

    public List<CommodityBrand>  listByCategoryId(Long categoryId) {
        return commodityBrandRepository.listByCategoryId(categoryId);
    }

    public List<CommodityBrand>  listByLetter(String letter) {
        return commodityBrandRepository.findByLetter(letter);
    }
}
